package com.train.mgr.modules.biz.controller;

import com.train.common.model.PageResult;
import com.train.common.model.R;
import com.train.mgr.modules.biz.dto.request.CourseQueryReqDTO;
import com.train.mgr.modules.biz.dto.request.CourseReqDTO;
import com.train.mgr.modules.biz.dto.response.CourseRespDetailDTO;
import com.train.mgr.modules.biz.dto.response.CourseRespListDTO;
import com.train.mgr.modules.biz.service.ICourseService;
import com.train.mgr.modules.system.dto.request.groups.Insert;
import com.train.mgr.modules.system.dto.request.groups.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 课程表 前端控制器
 * @author cxg
 * @date 2025-09-30
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@Api( tags = "课程管理[企业端]")
@RequestMapping("/course")
public class CourseController {

    private final ICourseService courseService;

    /**
     * 功能描述:单个获取 (仅作参考)
     * @author: cxg
     * @date: 2025-09-30
     */
    @GetMapping("/getById/{id}")
    @ApiOperation("查询详情")
    public R<CourseRespDetailDTO> getById(@PathVariable(name = "id") Long id) {
        return R.succeed(courseService.findDetailById(id));
    }


    /**
     * 条件 分页查询
     * @author: cxg
     * @date: 2025-09-30
     */
    @GetMapping("/page")
    @ApiOperation("分页查询课程列表")
    public R<PageResult<CourseRespListDTO>> page(CourseQueryReqDTO params) {
        return R.succeed(courseService.pageList(params));
    }

    /**
	 * 新增
     * @author: cxg
     * @date: 2025-09-30
	 */
    @PostMapping("/add")
    @ApiOperation("新增课程")
    public R<Long> add(@RequestBody @Validated(Insert.class) CourseReqDTO body) {
        return R.succeed(courseService.save(body));
    }

	/**
	 * 更新 (仅作参考)
     * @author: cxg
     * @date: 2025-09-30
	 */
    @PostMapping("/update")
    @ApiOperation("更新课程")
    public R<Boolean> update(@RequestBody @Validated(Update.class) CourseReqDTO body) {
        Boolean result = courseService.update(body);
        return R.succeed(result);
    }

	/**
	 * 删除
     * @author: cxg
     * @date: 2025-09-30
	 */
    @PostMapping("/delete/{id}")
    @ApiOperation("删除课程")
    public R<Boolean> delete(@PathVariable(name = "id") Long id) {
          Boolean result = courseService.deleteById(id);
          return R.succeed(result);
    }

    @PostMapping("/publish/{id}")
    @ApiOperation("发布课程")
    public R<Boolean> publish(@PathVariable(name = "id") Long id) {
        Boolean result = courseService.publish(id);
        return R.succeed(result);
    }

    @PostMapping("/unPublish/{id}")
    @ApiOperation("取消发布课程")
    public R<Boolean> unPublish(@PathVariable(name = "id") Long id) {
        Boolean result = courseService.unPublish(id);
        return R.succeed(result);
    }


    @PostMapping("/self_group")
    @ApiOperation("自选分组")
    public R<Boolean> selfGroup(@RequestParam(name = "courseId", required = true) Long id,
                                @RequestParam(name = "isSelfGroup", required = true) Long isSelfGroup) {
        Boolean result = courseService.selfGroup(id,isSelfGroup);
        return R.succeed(result);
    }


    @PostMapping("/check_review")
    @ApiOperation("是否免审核")
    public R<Boolean> checkReview(@RequestParam(name = "courseId", required = true) Long id,
                                @RequestParam(name = "isReview", required = true) Long isReview) {
        Boolean result = courseService.checkReview(id,isReview);
        return R.succeed(result);
    }
}
